from django.db import models

"""
1. 员工信息 ---- 来源于外部数据 
2. 产线信息 ---- Line [id, name]
3. 部门信息 ---- Department[id, name, line_id]
4. 职位信息 ---- Position [id, name, department_id]
5. 阶段名称 ---- PhaseName[id, name]
6. 阶段信息 ---- Phase[id, phasename_id, position_id]
7. 阶段内容 ---- PhaseContent[id,name, phase_id]
8. 提交培训记录的状态
   RecordStatus[id ,name]
     1 ---- InTraining  
     2 ---- Pass 
     3 ---- Fail 
   
   举例： 张三参加了某一个职位的培训 【三个阶段，每个阶段10个任务】
   Training Leader 提交培训信息 
    1. 张三   第一个阶段   第一个任务   InTraining [下次提交仍然是提交第一个阶段   第一个任务 ]
    2. 张三   第一个阶段   第一个任务   Pass/Fail [下次提交仍然是提交第一个阶段   第一个任务 ]
    3. 张三   第一个阶段   第二个任务
阶段一 

"""


class Line(models.Model):
    name = models.CharField(verbose_name="产线的名称", max_length=50, null=False, blank=False)

    class Meta:
        managed = True
        app_label = "basicweb"
        db_table = "Baisc_Line"
        verbose_name = "Line"
        verbose_name_plural = "Line"

    def __str__(self):
        return "%s" % (self.name)


class Department(models.Model):
    name = models.CharField(verbose_name="部门名称", max_length=50, null=False, blank=False)
    line = models.ForeignKey(verbose_name="产线", to=Line, on_delete=models.PROTECT)

    class Meta:
        managed = True
        app_label = "basicweb"
        db_table = "Baisc_Department"
        verbose_name = "Department"
        verbose_name_plural = "Department"

    def __str__(self):
        return "%s" % (self.name)


class Position(models.Model):
    name = models.CharField(verbose_name="职位名称", max_length=50, null=False, blank=False)
    department = models.ForeignKey(verbose_name="部门", to=Department, on_delete=models.PROTECT)

    class Meta:
        managed = True
        app_label = "basicweb"
        db_table = "Baisc_Position"
        verbose_name = "Positiont"
        verbose_name_plural = "Position"

    def __str__(self):
        return "%s" % (self.name)


class PhaseName(models.Model):
    name = models.CharField(verbose_name="阶段名称", max_length=50, null=False, blank=False)

    class Meta:
        managed = True
        app_label = "basicweb"
        db_table = "Baisc_PhaseName"
        verbose_name = "PhaseName"
        verbose_name_plural = "PhaseName"

    def __str__(self):
        return "%s" % (self.name)


class Phase(models.Model):
    phasename = models.ForeignKey(verbose_name="阶段名称", to=PhaseName, on_delete=models.PROTECT)
    position = models.ForeignKey(verbose_name="职位", to=Position, on_delete=models.PROTECT)

    class Meta:
        managed = True
        app_label = "basicweb"
        db_table = "Baisc_Phase"
        verbose_name = "Phase"
        verbose_name_plural = "Phase"


class PhaseContent(models.Model):
    name = models.CharField(verbose_name="阶段内容名称", max_length=100, null=False, blank=False)
    phase = models.ForeignKey(verbose_name="阶段", to=Phase, on_delete=models.PROTECT)

    class Meta:
        managed = True
        app_label = "basicweb"
        db_table = "Baisc_PhaseContent"
        verbose_name = "PhaseContent"
        verbose_name_plural = "PhaseContent"

    def __str__(self):
        return "%s" % (self.name)


class RecordStatus(models.Model):
    name = models.CharField(verbose_name="状态名称", max_length=50, null=False, blank=False)

    class Meta:
        managed = True
        app_label = "basicweb"
        db_table = "Baisc_RecordStatus"
        verbose_name = "RecordStatus"
        verbose_name_plural = "RecordStatus"

    def __str__(self):
        return "%s" % (self.name)
